<?php

require_once('../../tcpdf/tcpdf.php');
require_once('../../tcpdf/config/lang/eng.php');
include_once ('../../datos/AccesoDatos.php');
require_once ('../../genericos/translate.php');

class MYPDF extends TCPDF {

    //Page header
    public function Header() {
        // Logo
        $image_file = K_PATH_IMAGES . 'logo_example.jpg';
        $this->Image($image_file, 10, 10, 15, '', 'JPG', '', 'T', false, 300, '', false, false, 0, false, false, false);
        // Set font
        $this->SetFont('helvetica', 'B', 20);
        // Title
        $this->Cell(0, 15, '<< TCPDF Example 003 >>', 0, false, 'C', 0, '', 0, false, 'M', 'M');
    }

}



// extend TCPF with custom functions
// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->setPageOrientation('L');
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Nicola Asuni');
$pdf->SetTitle('TCPDF Example 006');
$pdf->SetSubject('TCPDF Tutorial');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');

// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, '', '');

// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));

//$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));

$pdf->setPrintFooter(false);
// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

//set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);

//set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

//set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

//set some language-dependent strings
$pdf->setLanguageArray($l);

// ---------------------------------------------------------
// set font
$pdf->SetFont('helvetica', '', 12);

// add a page
$pdf->AddPage();



$fechainicio = $_GET['fechainicio'];
$fechafin = $_GET['fechafin'];
$fechaRinicio = $_GET['fechaRinicio'];
$fechaRfin = $_GET['fechaRfin'];
$criterio = $_GET['criterio'];
$orderby = $_GET['orderby'];
    
    $sql = "pa_ReporteCitas('" .$fechainicio  . "','" . $fechafin . "','" . $fechaRinicio . "','" . $fechaRfin . "','" . $criterio . "','" . $orderby;
    $objDatos = new AccesoDatos();
    $objDatos->ejecutarConsulta($sql);
    while ($row = $objDatos->devuelveArreglo()) {
        
            $cuerpoCitas .= '<tr><td>' . $row['ds_empresa'] . '</td><td>' . $row['fc_inicio'] . '</td><td>' . $row['ds_codigo']. '</td><td>'  .  $row['empleado']. '</td><td>'  . $row['ds_identificacion'] . '</td><td>' . $row['paciente'] .'</td><td>' . _($row['ds_estadocita'])  . '</td><td>' . $row['usuario']. '</td><td>' . $row['fh_insert']  . '</td></tr>';
       
    }



// create some HTML content
$html = "<html><head>";

$html .= "<style>
table {
width:100%;
border-top:1px solid #e5eff8;
border-right:1px solid #e5eff8;
margin:1em auto;
border-collapse:collapse;
}
td {
color:#575757;
border-bottom:1px solid #e5eff8;
border-left:1px solid #e5eff8;
padding:.3em 1em;
text-align:center;
}
h4{
margin: 10px 10px;
}
</style>";
$html .= "</head><body>";
$html .= '<h4>' . _("informeGenCitas") . '</h4>';
$html .= '<table>';
$html .= '<tr><td bgcolor="#ccc">' . _("centromedico") . '</td><td bgcolor="#ccc">' . _("fechahora") . '</td><td bgcolor="#ccc">' . _("codigoempleado") . '</td><td bgcolor="#ccc">' . _("empleado") . '</td><td bgcolor="#ccc">' . _("cedula") . '</td><td bgcolor="#ccc">' . _("paciente") . '</td><td bgcolor="#ccc">' . _("estado") . '</td><td bgcolor="#ccc">' . _("usuario") . '</td><td bgcolor="#ccc">' . _("fecharegistro") .  '</td></tr>';
$html .= $cuerpoCitas;
$html .= '</table>';
$html .= '<p>'.  _("regsleidos") .': '.$objDatos->devuelveRegsLeidos() . '</p>';
$html .= "</body></html>";
// output the HTML content
$pdf->writeHTML($html, true, false, true, false, '');


// reset pointer to the last page
$pdf->lastPage();

// ---------------------------------------------------------
//Close and output PDF document
sleep(1);
$pdf->Output('citas.pdf', 'I');
